package com.iespring.service.app.catalog;

import com.iespring.bean.admin.category.DataBeanForCategory;
import com.iespring.bean.admin.category.bo.CategoryBo;
import com.iespring.bean.admin.category.po.CategoryPo;
import com.iespring.bean.common.BaseRespVo;
import com.iespring.mapper.app.CatalogWXBackMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @author weigwen
 * @Description:
 * @Date 2022/12/31 17:19
 */

@Service
public class CatalogServiceImpl implements CatalogService{

    @Autowired
    CatalogWXBackMapper catalogWXBackMapper;

    @Override
    public BaseRespVo catalogIndex() {
        List<CategoryPo> categoryList = catalogWXBackMapper.selectAllCatalogByPid(0);
        CategoryPo currentCategory = categoryList.get(0);
        List<CategoryPo> currentSubCategory = catalogWXBackMapper.selectAllCatalogByPid(categoryList.get(0).getId());
        DataBeanForCategory dataBeanForCategory = new DataBeanForCategory(currentCategory, categoryList, currentSubCategory);
        return BaseRespVo.ok(dataBeanForCategory);
    }

    @Override
    public BaseRespVo catalogCurrent(CategoryBo categoryBo) {
        CategoryPo currentCategory = catalogWXBackMapper.selectCatalogById(categoryBo);
        List<CategoryPo> currentSubCategory = catalogWXBackMapper.selectAllCatalogByPid(categoryBo.getId());
        DataBeanForCategory dataBeanForCategory = new DataBeanForCategory(currentCategory, null, currentSubCategory);
        return BaseRespVo.ok(dataBeanForCategory);
    }

}
